#!/usr/bin/env python
# encoding: utf-8
'''
@author: lx
@contact: lixiang-929@outlook.com
@file: bubblesort.py
@time: 2018/7/19 21:58
'''
def bubblesort(input_list):
    if len(input_list)==0:
        return []
    sorted_list = input_list
    for i in range(len(sorted_list)-1):
        flag = False
        print('第%d趟排序:' % (i+1))
        for j in range(len(sorted_list)-1):
            if sorted_list[j+1] < sorted_list[j]:
                sorted_list[j],sorted_list[j+1] = sorted_list[j+1],sorted_list[j]
                flag = True
            print(sorted_list)
        if not flag:
            break
    return sorted_list

if __name__ == '__main__':
    input_list = [3,2,21,45,57]
    print('排序前：',input_list)
    sorted_list = bubblesort(input_list)
    print('排序后：',sorted_list)